package com.hoko.blur.opengl.texture;

import ohos.agp.render.opengl.GLES20;
import ohos.media.image.PixelMap;


import com.hoko.blur.util.Preconditions;

import java.lang.ref.WeakReference;
import java.nio.Buffer;
import java.nio.IntBuffer;

/**
 * Created by yuxfzju on 2017/1/24.
 */

public class BitmapTexture extends Texture {

    private WeakReference<PixelMap> mBitmapWeakRef;

    BitmapTexture(PixelMap bitmap) {
        super(bitmap.getImageInfo().size.width, bitmap.getImageInfo().size.height);
        mBitmapWeakRef = new WeakReference<>(bitmap);
        create();

    }

    @Override
    protected void onTextureCreated() {
        if (width() != 0 && height() != 0 && mBitmapWeakRef != null) {
            PixelMap bitmap = mBitmapWeakRef.get();

            if (bitmap != null && !bitmap.isReleased()) {
//                GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
                System.out.println("zhangliang==>onTextureCreated");
//                GLES20.glCopyTexImage2D(GLES20.GL_TEXTURE_2D,0,0,0,0,bitmap.getImageInfo().size.width,bitmap.getImageInfo().size.height,0);
                GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D,0,0,bitmap.getImageInfo().size.width,bitmap.getImageInfo().size.height,0,0,0,null);
            }
        }
    }
}
